package com.kangyi.app.mapper;

import com.github.pagehelper.Page;
import com.kangyi.app.annotation.AutoFill;
import com.kangyi.dto.FavoriteDTO;
import com.kangyi.dto.ToggleFavoriteDTO;
import com.kangyi.dto.UserPageDTO;
import com.kangyi.entity.NursingHomeFavorite;
import com.kangyi.enumeration.OperationType;
import com.kangyi.vo.FavoritesVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author Blank
 * @version 1.0
 */
@Mapper
public interface NursingHomeFavoriteMapper {


    @Select("select * from nursing_home_favorite where user_id = #{userId} and nursing_home_id = #{nursingHomeId}")
    NursingHomeFavorite selectByUserIdAndNursingHomeId(FavoriteDTO build);

    @Insert("insert into nursing_home_favorite(user_id, nursing_home_id, create_time, update_time, create_user, update_user) " +
            "VALUES(#{userId},#{nursingHomeId},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    @AutoFill(value = OperationType.INSERT)
    void addFavorite(NursingHomeFavorite nursingHomeFavorite);

    @Delete("delete from nursing_home_favorite where user_id = #{userId} and nursing_home_id = #{nursingHomeId};")
    void cancelFavorite(ToggleFavoriteDTO toggleFavoriteDTO);

    @Select("select * from nursing_home_favorite where user_id = #{userId} and nursing_home_id = #{nursingHomeId}")
    NursingHomeFavorite select(Integer userId, Integer nursingHomeId);

    Page<FavoritesVO> favoritesList(UserPageDTO userPageDTO);
}
